﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Data;

namespace hpm
{
    class DAL
    {
        public SqlConnection con = new SqlConnection();
        public string connString = "";
        public void da_connect(string servername, string username, string password, string databasename)
        {
            connString = String.Format("server={0};User id={1};password={2};database = {3}", servername, username, password, databasename);
            con = new SqlConnection(connString);
        }


        public void ketnoiServer()
        {
            this.da_connect("PHANMEM-PC\\QUESTION", "sa", "sa", "hpm");
            this.da_openConnect();
        }


        public void da_openConnect()
        {
            try
            {
                con.Open();
                //MessageBox.Show("Mo thanh cong");
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message);
                MessageBox.Show("Không kết nối được cơ sở dữ liệu");
            }
        }

        public void da_closeConnect()
        {
            if (con.State != ConnectionState.Closed)
            {
                con.Close();
                con.Dispose();
                //MessageBox.Show("Dong ket noi");
            }
        }
    }
}
